package com.processmining.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.processmining.dao.AlgoMapper;
import com.processmining.entity.Algo;
import com.processmining.service.IAlgoService;
import com.processmining.util.Config;
import com.processmining.util.ConfigParser;
import com.processmining.util.Param;
import com.processmining.util.response.Code;


@Service
public class AlgoServiceImpl implements IAlgoService {
	@Autowired
	private AlgoMapper algoMapper;

	@Override
	public int createAlgo(Algo algo) {
		return algoMapper.insertSelective(algo) == 1 ? Code.SUCCEED : Code.SYSTEM_ERROR;
	}

	@Override
	public int deleteAlgoById(int algoId) {
		return algoMapper.deleteByPrimaryKey(algoId) == 1 ? Code.SUCCEED : Code.SYSTEM_ERROR;
	}

	@Override
	public Algo getAlgoById(int algoId) {
		return algoMapper.selectByPrimaryKey(algoId);
	}

	@Override
	public List<Algo> getAllAlgo() {
		return algoMapper.listAllAlgo();
	}
	
	@Override
	public List<Algo> listMiningAlgo(){
		return algoMapper.listMiningAlgo();
	}
	
	@Override
	public List<Algo> listMergeAlgo(){
		return algoMapper.listMergeAlgo();
	}

	@Override
	public Config getAlgoConfig(Integer algoId) {
		Algo algo = algoMapper.selectByPrimaryKey(algoId);
		Config config = ConfigParser.parseConfig(algo.getConfigpath());
		return config;
	}


	
}